﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class 测试相关代码 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        测试1();


        数组复制();

        最大车速();
    }



    public void 测试1()
    {
          byte[] bytHeadOfBag = new Byte[2] { 0xff, 0xef };   
          
         var strHeadOfBag = System.Text.Encoding.GetEncoding("GB2312").GetString(bytHeadOfBag.Reverse().ToArray()); 
    }


    public int 最大车速()
    {
        List<byte> arr = new List<byte>();
        int a = 999;
        int b = a / 100 & 0x0f;
        int c = (a % 100) / 10 & 0x0f;
        int d = (a % 10) & 0x0f;
        c = (c << 4 | d);
        arr.Add((byte)b);
        arr.Add((byte)c);

        int arrx = BitConverter.ToInt16(arr.ToArray(), 0);




        //反解BCD码
        //车速百位	BCD	1  十六进制  数字
        byte h100 = arr[0];


        //十位，个位	BCD	 十六进制  数字
        byte hGe = arr[1];

        int bai = int.Parse(h100.ToString("X2")) * 100;
        int ge = int.Parse(hGe.ToString("X2"));
        //计算车速
        int MaxSpead = bai + ge;

        return arrx;
    }


    public void 数组复制()
    {
        string asc = "sdfdsfsdffdswerweriweurwpoeiropwei210482390840238409238094823";
        List<byte> arr = new List<byte>();
        arr.Add((byte)asc.Length);
        arr.AddRange(System.Text.ASCIIEncoding.ASCII.GetBytes(asc));

        var buff=arr.ToArray();
       int offset=0;
        //dbc文件名长度
                byte len = buff[offset];
                offset += 1;
                //DBC文件名内容
                var  DBCFileName = System.Text.Encoding.GetEncoding("gb2312").GetString(buff, offset, len);
                offset += len;
          bool cb=asc==DBCFileName;

    }
}